import {Router} from 'express';
import PayOrder from "../db/entity/PayOrder";
import {Op} from 'sequelize';

let router = Router();

router.get('/count', count);

async function query(start, end) {


    let hour = await PayOrder.count({
        where: {
            [Op.and]: [
                {
                    createAt: {
                        [Op.gt]: new Date(start)
                    }
                },
                {
                    createAt: {
                        [Op.lt]: new Date(end)
                    }
                }
            ]
        },
    });
    return JSON.stringify(hour);
}

async function count(req, res) {
    let rep = await query(req.query.start, req.query.end);
    res.send(rep);
}

module.exports = router;
